<?php

class AutoFileLoader  {
	const FILE_XML = 'xml';
	const FILE_HTML = 'html';
	
	private static $basePath = null;
	
	public static function setBasePath ($basePath)  {
		if (!is_null($basePath))  {
			self::$basePath = $basePath. '/files';
		}
	}
	
	public static function getFileContent ($fileinfo, $filename)  {
		switch ($fileinfo)  {
			case self::FILE_XML:
				$content = self::getXMLFileContent($filename);
				break;
			case self::FILE_HTML:
				$content = self::getHTMLFileContent($filename);
				break;
		}
		
		return $content;
	}
	
	private static function getXMLFileContent ($filename)  {
		$combinedPath = self::$basePath. '/'. self::FILE_XML. '/'. $filename. '.xml';
		$xml = new DOMDocument('1.0', 'utf-8');
		$xml->loadXML(ArrayProcessor_XMLElements::removeWhitespace($combinedPath));		
		return $xml;
	}
	
	private static function getHTMLFileContent ($filename)  {
		$combinedPath = self::$basePath. '/'. self::FILE_HTML. '/'. $filename. '.html';
		$file = file_get_contents($combinedPath);
		return $file;
	}
}